﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace scmsByAspdNet.cotro.admin {
  /// <summary>
  /// addCourse 的摘要说明
  /// </summary>
  public class addCourse : IHttpHandler {

    public void ProcessRequest(HttpContext context) {
      //数据处理
      //string id = context.Request["id"].ToString(),
      string title = context.Request["title"].ToString(),
      credit = context.Request["credit"].ToString(),
      hour = context.Request["hour"].ToString(),
      attribute = context.Request["attribute"].ToString(),
      proportion = context.Request["proportion"].ToString(),
      faculty = context.Request["faculty"].ToString(),
      comment = context.Request["comment"].ToString(),
      cover = context.Request["cover"] == null ? "null" : context.Request["cover"].ToString(),
      status = context.Request["status"].ToString();
      //数据库
      SqlConnection conn = new SqlConnection("Data Source=106.54.69.143;database=scms;uid=sa;pwd=Aspdotnet666");
      conn.Open();
      //声明返回的数据
      string ret = "";
      //创建SQL命令
      string sql = $"insert into sc_course(title,credit,hour,attribute,proportion,faculty,comment,cover,status,is_deleted) values ('{title}',{credit},{hour},{attribute},{proportion},'{faculty}','{comment}','{cover}',{status},0);";
      SqlCommand cmd = new SqlCommand(sql, conn);
      //执行SQL命令
      int res = cmd.ExecuteNonQuery();
      //获取SqlDataReader
      conn.Close();
      //返回数据
      context.Response.StatusCode = 200;
      context.Response.Write($"{{\"code\":0,\"lines\":{res}}}");
    }

    public bool IsReusable {
      get {
        return false;
      }
    }
  }
}